package com.sky.controller.admin;

import com.sky.constant.JwtClaimsConstant;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.pojo.Employee;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.EmployeeService;
import com.sky.utils.JwtUtil;
import com.sky.vo.EmployeeByIdVO;
import com.sky.vo.EmployeeLoginVO;
import com.sky.vo.EmployeeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/employee")
@Slf4j
@Api(tags = "员工管理")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    // 修改员工资料
    @ApiOperation("修改员工资料")
    @PutMapping
    public Result<?> editEmpById(@RequestBody EmployeeDTO employeeDTO) {
        log.info("修改员工资料：{}", employeeDTO);
        employeeService.editEmpById(employeeDTO);
        return Result.success();
    }

    // 根据id查询员工
    @ApiOperation("根据id查询员工")
    @GetMapping("/{id}")
    public Result<EmployeeByIdVO> getEmpById(@PathVariable Long id) {
        log.info("根据id查询员工：{}",id);
        return employeeService.getEmpById(id);
    }

    // 启用禁用员工账户
    @ApiOperation("启用禁用员工账户")
    @PostMapping("/status/{status}")
    public Result<?> startOrStop( @PathVariable Integer status, @RequestParam long id ) {
        log.warn("员工状态：{}",status);
        employeeService.startOrStop(status,id);
        return Result.success();
    }


    @ApiOperation("员工分页查询")
    @GetMapping("/page")
    public Result<PageResult<EmployeeVO>> empListByPage(EmployeePageQueryDTO employeePageQueryDTO){
        log.info("员工分页查询：{}",employeePageQueryDTO);

        PageResult<EmployeeVO> pageResult = employeeService.empListByPage(employeePageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("新增员工")
    @PostMapping
    public Result<String> addEmp(@RequestBody EmployeeDTO employeeDTO){
        log.info("员工信息：{}",employeeDTO);
        return employeeService.addEmp(employeeDTO);
    }
    /**
     * 登录
     *
     * @param employeeLoginDTO
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("员工登录")
    public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
        log.info("员工登录：{}", employeeLoginDTO);
        return employeeService.login(employeeLoginDTO);

    }


    /**
     * 退出
     *
     * @return
     */
    @PostMapping("/logout")
    @ApiOperation("员工退出")
    public Result<String> logout() {
        return Result.success();
    }



}
